package com.dyh.quickdemo.GoodsRules;

import com.alibaba.fastjson.JSON;
import org.springframework.util.StringUtils;

import static com.dyh.quickdemo.GoodsRules.Rule$1Builder.when;
import static com.dyh.quickdemo.GoodsRules.Rules.*;

/*
@Author=Joey Wheeler
@Date=2021/3/6 10:59
*/
public class GoodsChecker {

//    public static String check(Goods goods, List<Rule<Goods,?> > rules){
//        for (Rule<Goods,?> rule : rules) {
//            System.out.println( rule.check(goods));
//        }
//        return "";
//    }

    public static void main(String[] args) {
        Goods goods = new Goods();
        goods.setTitle("11111111111");
        goods.setAutoSupplement(10);
//        goods.setOnSale(true);
//
//        Checker$2<Boolean,Integer> checker$2 =
//            (aBoolean, integer) -> integer>0?aBoolean:false;
//        Rule$2Builder.when(Goods::isOnSale,Goods::getAutoSupplement)
//                .must(checker$2,"")
//                .build();

        CheckResult checkResult = check(
                    goods,
                        when(Goods::getTitle)
                        .must(not(StringUtils::isEmpty),"标题不能为空")
                        .must(e->e.length()<5,"长度不能超过5").build()

//                        Rule$2Builder.when(Goods::isOnSale,Goods::getAutoSupplement)
//                        .must((onsale,autoSupplement)->autoSupplement>0?onsale:true,"必须为上架状态")
//                                .build()
                );

        System.out.println(JSON.toJSONString(checkResult));
    }
}
